<template>
  <div class="new">
    <Title></Title>
    <div class="new_box">
      <div class="inner">
        <div class="new_tab">
          <div class="newtab_item" style="color: white" v-for="(item,index) in newclass" :key="index" @click="newstab(index,item.news_class_id)" :class="[tabid === index ? 'newactive':'']">
            {{item.news_class_name}}
          </div>
        </div>
        <div class="new_list" v-if="newlist.length>0">
          <div class="new_item" v-for=" (item,index) in newlist" :key="index" @click="pageurl(item.news_id)">
            <div class="new_img">
              <img :src="[item.news_img]" alt="">
            </div>
            <div class="new_info">
              <div class="newcontent">
                    {{item.news_name}}
              </div>
              <div class="new_drop">
                <div class="new_left">
                  {{item.view_num}}人浏览
                </div>
                <div class="new_time">
                  {{item.create_time_text}}
                </div>
              </div>
            </div>
          </div>
          <el-pagination
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-size="page_size"
                layout="total, prev, pager, next, jumper"
                :total="totalnum">
          </el-pagination>
        </div>
        <div class="new_none" v-else>
          没有数据
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import Title from "../../components/title.vue"
  import {newsapi} from "../../api/http.js"
  export default {
    name: 'new',
    components: {
      Title
    },
    data(){
      return{
        newclass:{},
        newlist:[],
        page_size:5,
        page:1,
        classid:"",
        totalnum:"",
        tabid:0
      }
    },
    created(){
      this._getnew({class_id:"",page_size:this.page_size,page:this.page})
    },

    methods:{
      newstab(index,classid){
        this.tabid= index
        this.classid= classid
        this.totalnum=""
        this._getnew({class_id:classid,page_size:this.page_size,page:this.page})
      },
      handleCurrentChange(val) {
         this._getnew({class_id:this.classid,page_size:this.page_size,page:val})
      },
      pageurl(id){
          this.$router.push({
            path:"/newdetail",
            query: {
              id: id
            }
          })
      },
     async _getnew({class_id,page_size,page}){
        const res = await newsapi({class_id,page_size,page})
        if(res.data.code===200){
          console.log(res.data.data.data.data);
          this.newclass= res.data.data.class
          this.newlist= res.data.data.data.data
          this.totalnum= res.data.data.data.total
        }else{
          this.newdata=[]
        }
      }
    }
  }
</script>

<style lang="less">
  .new_box {
    width: 100%;
    .inner {
      width: 1300px;
      padding: 0 100px;
      box-sizing: border-box;
      margin: 0 auto;

      .new_tab {
        width: 100%;
        height: 40px;
        display: flex;
        justify-content: flex-start;
        margin-bottom: 5px;
        .newtab_item {
          padding: 0 30px;
          font-weight: 400;
          line-height: 40px;
          font-size: 14px;
          color: #292929;
          position: relative;
        }
        .newactive:before{
          content: "";
          display: block;
          width: 50px;
          height: 2px;
          position: absolute;
          bottom: 0;
          left: 50%;
          margin-left: -25px;
          background-color: #FF4444;
        }
      }
      .new_none{
        width: 100%;
        height: 200px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 14px;
        box-sizing: border-box;
        background: rgba(196, 196, 196, 0.11);
        border: 0.5px solid #CCCDCE;
      }
      .new_list {
        width: 100%;
        padding:15px 25px;
        box-sizing: border-box;
        background: rgba(196, 196, 196, 0.11);
        border: 0.5px solid #CCCDCE;
        .new_item {
          width: 100%;
          display: flex;
          justify-content: flex-start;
          margin-bottom: 20px;
          background-color: #fff;
          .new_img {
            width: 265px;
            height: 198px;

            img {
              width: 265px;
              height: 198px;
            }
          }
          .new_info {
            padding: 15px;
            width: 705px;
            padding-left: 20px;
            box-sizing: border-box;
            display: flex;
            justify-content: space-between;
            flex-direction: column;
            .newcontent {
              width: 100%;
              font-weight: 400;
              font-size: 16px;
              line-height: 22px;
              color: #292929;
            }

            .new_drop {
              display: flex;
              justify-content: space-between;
              font-weight: 400;
              font-size: 16px;
              color: #999999;
              .new_left {
                width: 50%;
                text-align: left;
              }
              .new_time {
                width: 50%;
                text-align: right;
              }
            }
          }
        }
      }
    }
  }
</style>
